"use strict";
/**
 * 在类中使用装饰器
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const moveDecorators = (target) => {
    console.log("target", target); // target [Function: Tank]
    /**
     * 可以看到这里的 Tank 实际上就是构造函数 [Function: Tank]  所以装饰器基于原型链是可以在构造函数上添加属性和方法的
     */
    target.prototype.name = "Jimmy";
    target.prototype.getPosition = (x, y) => {
        return { x: 300, y: 400 };
    };
};
let Tank = class Tank {
};
Tank = __decorate([
    moveDecorators
], Tank);
let t1 = new Tank();
//
/**
 * name属性是基于装饰器，装饰器通过获取构造函数在原型链上添加的 所以因为TS类型检查会找不到自身的name会报错，
 *  我们直接这样使用是不行的  需要使用断言
 * console.log("t1...", t1.name);
 */
// 使用断言正常获取
console.log("t1...", t1.name);
// console.log("t1...", (<any>t1).name);
let Hero = class Hero {
};
Hero = __decorate([
    moveDecorators
], Hero);
let h1 = new Hero();
console.log("hero!!", h1.name);
console.log("hero!!", h1.getPosition());
